package com.eedi.framework.protocol.service;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.collection.CollectionUtils;
import com.eedi.framework.protocol.controller.sys.vo.SysProtocolHistoryPageReq;
import com.eedi.sys.facade.SysUserFacade;
import com.eedi.framework.protocol.dal.dataobject.ProtocolHistoryDO;
import com.eedi.framework.protocol.dal.mapper.ProtocolHistoryMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.stream.Collectors;


/**
 * 协议配置历史版本 Service 实现类
 *
 * @author 永聚长青源码
 */
@Service
@Validated
public class SysProtocolHistoryServiceImpl implements SysProtocolHistoryService {

    @Resource
    private ProtocolHistoryMapper protocolHistoryMapper;

    @Resource
    private SysUserFacade sysUserFacade;


    @Override
    public ProtocolHistoryDO getProtocolHistory(String systemProtocolHistoryId) {
        return protocolHistoryMapper.selectById(systemProtocolHistoryId);
    }

    @Override
    public PageResult<ProtocolHistoryDO> getProtocolHistoryPage(SysProtocolHistoryPageReq pageReqVO) {
        PageResult<ProtocolHistoryDO> page = protocolHistoryMapper.selectPage(pageReqVO);
        page.getList().stream().map(ProtocolHistoryDO::getSysProtocolDesc).collect(Collectors.toList());
        if(CollectionUtils.isAnyEmpty(page.getList())){
            return PageResult.empty();
        }
        sysUserFacade.fillInUserName(page.getList(),ProtocolHistoryDO::getCreator,ProtocolHistoryDO::setCreator);
        return page;
    }

}
